package com.lvtongka.app.ui.qr

import android.content.Intent
import android.os.Bundle
import android.text.TextUtils
import android.view.View
import com.lvtongka.app.base.BaseVBActivity
import com.lvtongka.app.common.CommonUtils
import com.lvtongka.app.databinding.ActivityPaymentCompletedBinding
import com.lvtongka.app.http.common.WebConstants
import com.lvtongka.app.ui.webview.WebViewActivity

/**
 * 支付完成
 */
class PaymentCompletedActivity : BaseVBActivity<ActivityPaymentCompletedBinding>() {
    private var isCoupon = false
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        initEvent()
        initData()
    }

    override fun initEvent() {
        binding.header.imgBack.setOnClickListener {
            setResult(RESULT_OK)
            finish()
        }
        binding.tvCompleted.setOnClickListener {
            if (isFastClick()) {
                return@setOnClickListener
            }
            if (isCoupon) {
                jumpWeb(WebConstants.COUPON_TRAN_LIST)
            } else {
                jumpWeb(WebConstants.PAY_INFO_LIST)
            }
            setResult(RESULT_OK)
            finish()
        }
    }

    override fun initData() {
        binding.header.tvTitle.text = "支付订单"
        binding.header.imgBack.visibility = View.VISIBLE
        binding.header.statusBarView.layoutParams.height = CommonUtils.getStatusBarHeight()

        val balance = intent.getStringExtra("balance")
        val name = intent.getStringExtra("name")
        val payResult = intent.getStringExtra("payResult")
        if (intent.hasExtra("isCoupon")) {
            isCoupon = intent.getBooleanExtra("isCoupon", false)
        }
        if (TextUtils.equals("支付失败", payResult)) {
            binding.llSuccess.visibility = View.GONE
            binding.ivError.visibility = View.VISIBLE
        } else {
            binding.llSuccess.visibility = View.VISIBLE
            binding.ivError.visibility = View.GONE
        }

        binding.tvPayResult.text = payResult
        binding.tvBalance.text = "¥$balance"
        binding.tvShName.text = name
    }

    override fun initBinding(): ActivityPaymentCompletedBinding {
        return ActivityPaymentCompletedBinding.inflate(layoutInflater)
    }
}